﻿using RabbitMQ.ServiceModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;

namespace MessageQuque.Server
{
    public class Host
    {
        private static ServiceHost m_host;

        public static void StartService()
        {
            try
            {
                RabbitMQBinding binding = new RabbitMQBinding(Config.Server, Config.Port,
                    Config.UserName, Config.Password, Config.VirtualHost,
                    Config.MaxSize, RabbitMQ.Client.Protocols.FromConfiguration("protocol"));

                m_host = new ServiceHost(typeof(MessageQuqueService), new Uri("soap.amqp:///"));
                binding.OneWayOnly = true;
                m_host.AddServiceEndpoint(typeof(IMessageQuqueContract), binding, "MessageQuqueService");
                m_host.Open();
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(e.ToString());
            }
        }
    }
}
